define(function (require) {
    require('validate');
    var Base = require('group/common/main');
    var utils = require('common/utils/home');
    var Mask = require('common/mask');
    var mask = new Mask();
    var ModalTpl = require('text!./templates/modal.html');

    var animate_time = 'fast';
    return Base.extend({
        initialize: function (params) {
            var _this = this;
            Base.prototype.initialize.apply(_this, [params]);

            _this.params = _.extend({mask_disable: false}, params);
        },
        render_modal: function (data) {
            var _this = this;
            var index;
            if (data.index) {
                index = data.index;
            }
            else {
                index = window.Z_INDEX++;
            }
            data = _.extend(data, {
                name: _this.name,
                _id: _this.id,
                width: document.documentElement.clientWidth + 'px',
                height: document.documentElement.clientHeight + 'px',
                index: index
            });
            var html = _this.render(ModalTpl, data);
            $('body').append(html);

            if (!_this.params.mask_disable) {
                _this.get_modal_mask().click(function () {
                    _this.hide();
                });
            }
        },
        show: function () {
            var _this = this;
            _this.get_modal_mask().css({opacity: 0}).show().animate({opacity: 0.6}, animate_time);

            _this.get_modal_content().css({'bottom': '-' + document.documentElement.clientHeight + 'px'}).show().animate({bottom: '0px'}, animate_time);
        },
        hide: function () {
            var _this = this;

            _this.get_modal_mask().animate({opacity: 0}, animate_time, function () {
                _this.get_modal_mask().hide();
            });
            _this.get_modal_content().animate({bottom: '-' + _this.get_modal_content().height() + 'px'}, animate_time, function () {
                _this.get_modal_content().hide();
            });
        },

        get_modal_content: function () {
            var _this = this;
            return $('#' + _this.id + ' .modal-content');
        },
        get_modal_mask: function () {
            var _this = this;
            return $('#' + _this.id + '_mask');
        },
        is_create: function () {
            var _this = this;
            return $('#' + _this.id).size() > 0;
        }
    });
});